<template>
    <view>
		<dataTable :thList="thList" :isflag="isflag" :colWidthList="colWidthList" :thBgColor="fontcolor.color" thColor="#fff" thSize="30"
		    thHeight="70" :borderColor="fontcolor.color" :tbList="tbList">
		</dataTable>
		 <mx-date-picker  :show="showPicker" :type="type" :value="value" :show-tips="true"  :show-seconds="true" @confirm="ed" @cancel="ed" />
     <sa-hover-menu :sumcount=sumcount :flag1="flag1"></sa-hover-menu>	
	</view>
</template>

<script>
	import saHoverMenu from '../../components/sa-hover-menu/sa-hover-menu.vue';
	import dataTable from '../../components/lun-dataTable/lun-dataTable.vue'
	import MxDatePicker from "@/components/mx-datepicker/mx-datepicker.vue";
	export default {
		components: {
			dataTable,
			MxDatePicker,
			saHoverMenu
		},
		data() {
			return {
				sumcount:0,
				flag1:1,
				fontcolor:{
				color:this.$kdup.color,
				borderBottom:'2px solid '+this.$kdup.color
				},
				bj:{
				backgroundColor:this.$kdup.color,
				},
				color:this.$kdup.color,
				date: this.addDate(new Date(),"0"),
				type: 'date',
				showPicker: false,
				value: '',
				isflag:"1",
				thList: ['汇报单号','生产订单','排产单号','物料','规格型号', '边检员', '机台','数量', '工序','班组','排班'],
				colWidthList: ['300','300','300','300', '300', '200', '200' , '200', '200', '200', '200'],
				tbList: [
				],
				curWord:""
			}
		},
		onLoad() {  
			uni.setNavigationBarColor({
				frontColor: "#ffffff",	//文字颜色
				backgroundColor: this.$kdup.color	//底部背景色
			})
			this.InitData(this.curWord,this.date);
		},
		methods: {
	      InitData(curWord,datetime){
			  var where="";
		  if(!this.$kdup.isEmpty(curWord)){
			  where="and e.FBTPCBILLNO like'%"+curWord+"%'";
		  }
		var data={sql:"/*dialect*/select g.FBILLNO 汇报单号,c.F_TOP_SOURCEBILLNO 生产订单,c.FBTPCBILLNO 排产编号,m.FNAME 物料名称,m.FSPECIFICATION 规格型号,p.FNAME 边检员,j.FNAME 机台,SUM(cast(g1.FHBQTY as float)) 数量,g2.FNAME 工序,s.fname 班组,case when c.FDUTYWORK1='A' THEN '白班' else '夜班' end  排班"+
		"  from top_t_HBGX g inner join top_t_HBGXEntry g1 on g.FID=g1.fid  inner join top_t_Cust_Entry100011 c "+
		"   on c.FBTPCBILLNO=g1.FSRCPCBTBNO inner join T_BD_MATERIAL_L m on g1.FMATERIALID=m.FMATERIALID inner join T_HR_EMPINFO_L p  "+ 
		"   on c.FEMPCHECK=p.FID  inner join KDUP_t_JTSJ_L j on j.FID=g1.F_TOP_JTBH inner join top_t_GXXL_L g2 on g2.FID=g1.FHEADGX inner join T_PRD_SHIFTGROUP_L s on s.FID=c.FPB "+
		"   where c.FBTPCBILLNO!='' and c.FGX!='' and Convert(varchar(10),g.FCREATEDATE,121)='"+datetime+"'"+ where+
		"     group by m.FNAME,m.FSPECIFICATION,p.FNAME,j.FNAME,g2.FNAME,c.FSCNAME,c.FBTPCBILLNO,c.FDUTYWORK1,s.fname,g.FBILLNO,c.F_TOP_SOURCEBILLNO   order by SUM(cast(g1.FHBQTY as float))  desc "
		}
		  uni.showLoading({title: '数据加载中',mask:true});
			  this.$myRequest.postRequest("LoadListJson", data).then(res => {
				 this.tbList=[];
				if (res.data.error != "") {
					 uni.showToast({
						title:"找不到排产单！",
						duration: 2000,
						icon: "none"
					 });
					return;
					}
				this.sumcount=0;
				for(var i=0;i<res.data.Table.length-1;i++){
				 this.tbList.push(Object.values(res.data.Table[i]));	
				this.sumcount+=parseInt(res.data.Table[i]["数量"]);
				}
					setTimeout(function () {uni.hideLoading();}, 100);
			  })
		  },
		  onNavigationBarSearchInputConfirmed(e) {
		  			this.curWord = e.text 
		  			this.InitData(this.curWord,this.date);
		  },
		  onNavigationBarSearchInputChanged(e) {
		  		 	this.curWord = e.text 
		  			this.InitData(this.curWord,this.date);
		  },
		  DatePicker(type){//显示
		      this.type = type;
		      this.showPicker = true;
		      this.value = this[type];
		  },
		  ed(e) {//选择
		      this.showPicker = false;
		      if(e) {
		          this[this.type] = e.value; 
		          this.date=e.value;
				 this.InitData(this.curWord,this.date);
		      }
		  },
		  onNavigationBarButtonTap(e) {
		  this.DatePicker('date');
		  },
		  //获取今天日期，格式YYYY-MM-DD
		  addDate(date, days) {
		  			   if(days == undefined || days == '') {
		  				   days = 1;
		  			   }
		  			   var date = new Date(date);
		  			   date.setDate(date.getDate() - days);
		  			   var month = date.getMonth() + 1;
		  			  var day = date.getDate();
		  			  var mm = "'" + month + "'";
		  			  var dd = "'" + day + "'";
		  			  
		  			  //单位数前面加0
		  			  if(mm.length == 3) {
		  				  month = "0" + month;
		  			  }
		  			  if(dd.length == 3) {
		  				  day = "0" + day;
		  			  }
		  			  var time = date.getFullYear() + "-" + month + "-" + day
		  			  return time;
		   }
		}
	}
</script>

<style>

</style>
